﻿module Ast

type id = string

type Info = int * int

type Program = 
  ClassDecl list

and ClassDecl = 
  ClassDecl of id * (id option) * FieldOrMethodDecl list

and FieldOrMethodDecl = 
  | FieldDecl of Type * id * id list * Info
  | MethodDecl of ReturnType * id * Arg list * Block * Info
  with member this.IsField = match this with
                             | FieldDecl _ -> true
                             | MethodDecl _ -> false
       member this.IsMethod = not this.IsField 


//and fieldDecl =
//  FieldDecl of ty * id * id list
//
//and methodDecl =
//  MethodDecl of returnTy * id * arg list * block

and Arg =
  Arg of Type * id
  
and ReturnType = 
  | Type of Type
  | Void

and Type =
  | Integer
  | Boolean
  | String
  | Identifier of string
  | Array of Type

and Block = 
  Block of VarDecl list * Stmt list * Info

and VarDecl =
  VarDecl of Type * (id * (Expr option)) * (id * (Expr option)) list * Info

and Stmt =
  | Assign of Location * Expr * Info
  | Call of Call * Info
  | Return of (Expr option) * Info
  | If of Expr * Stmt * (Stmt option) * Info
  | While of Expr * Stmt * Info
  | Block of Block
  | Break of Info
  | Continue of Info

//and assign =
//  Assign of 

and Location =
  | Id of id
  | Member of Expr * id * Type option ref
  | Nth of Expr * Expr
  
and Call =
  Call of Method * Expr list

and Method =
  | Method of id
  | Select of Expr * id * Type option ref

//and Actuals =
//  Actuals of Expr * Expr list

and Expr =
  | Location of Location
  | Call of Call
  | New of id
  | NewArray of Type * Expr
  | Length of Expr
  | Binary of Expr * Binary * Expr
  | Unary of Unary * Expr
  | Literal of Literal
//  | Bracket of Expr
  | This

and Binary =
  | Sum of bool ref
  | Minus
  | Mul
  | Div
  | Mod
  | And
  | Or
  | Min
  | MinEq
  | Greater
  | GreaterEq
  | Eq
  | NotEq

and Unary =
  | Negative
  | Not

and Literal =
  | Int of int
  | Str of string
  | Bool of bool
  | Null
    
